import {Index} from '../index/index-model.js';
import {Detail} from '../goodsDetail/detail-model.js';
var detail = new Detail();
var index = new Index();
var app = getApp();
Page({
  data: {

  },
  onLoad(options){
    if(options.type)
    {
       index.searchProduct(options.name,(data)=>{
         var product = data.data;
         for(let i=0;i<product.length;i++)
         {
           product[i].goods_price = parseInt(product[i].goods_price/31)
         }
        
      this.setData({
          productArr:data.data
        })
    })
    }else{
      index.getCategoryProducts(options.id,(data)=>{
        var products = data.data;
        for(let i=0;i<products.length;i++)
        {
          products[i].goods_price = parseInt(products[i].goods_price/31)
        }
        this.setData({
          productArr:data.data
        })
    })
    }
   
  },

  //点击进入商品详情
  goProductDetail(e)
  {
    var id = e.currentTarget.dataset.id;
   my.navigateTo({
     url:"/pages/goodsDetail/goodsDetail?id="+id
   });
  }
});
